package com.fone.player.play.adapter;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fone.player.ApplicationManage;
import com.fone.player.R;
import com.fone.player.client.CommentlistRst.Comment;
import com.fone.player.play.adapter.GridSeriesItemAdapter.ViewHolder;

public class VideoCommentAdapter extends BaseAdapter {


	private List<Comment> comments;

	public VideoCommentAdapter() {
		super();
	}

	@Override
	public int getCount() {
		if (comments == null) {
			return 0;
		}
		return comments.size();
	}

	@Override
	public Object getItem(int position) {
		if (comments == null) {
			return null;
		}
		return comments.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		Comment comment = comments.get(position);
		if (convertView == null) {
			convertView = LayoutInflater.from(ApplicationManage.getAplicationManageInstance()).inflate(R.layout.video_comment_list_item, null);
			holder = new ViewHolder((TextView) convertView.findViewById(R.id.video_comment_item_name), (TextView) convertView.findViewById(R.id.video_comment_item_date), (TextView) convertView.findViewById(R.id.video_comment_item_content),
					(TextView) convertView.findViewById(R.id.video_comment_item_from));
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.name.setText(comment.name);
		holder.date.setText(comment.time);
		holder.content.setText(comment.text);
		if (!TextUtils.isEmpty(comment.comefrom) && comment.comefrom.equals("豆瓣")) {
			holder.from.setVisibility(View.VISIBLE);
			holder.from.setText(ApplicationManage.getAplicationManageInstance().getString(R.string.comment_from) + comment.comefrom);
		} else {
			holder.from.setVisibility(View.GONE);
		}
		convertView.setTag(holder);

		return convertView;
	}

	private class ViewHolder {
		public TextView name;
		public TextView date;
		public TextView content;
		public TextView from;

		public ViewHolder(TextView name, TextView date, TextView content, TextView from) {
			super();
			this.name = name;
			this.date = date;
			this.content = content;
			this.from = from;
		}
	}

	public void setData(List<Comment> comments) {
		this.comments = comments;
		notifyDataSetChanged();
	}

}
